package service

import (
	"context"
	"devops-super/api"
	v1 "devops-super/api/product/v1"
	"devops-super/internal/model/entity"
	"devops-super/internal/model/mymodel"
)

// IDevice 设备服务接口
type IDevice interface {
	// Add 新增设备
	Add(ctx context.Context, req *v1.DeviceAddReq) (res *v1.DeviceAddRes, err error)

	// Upt 更新设备
	Upt(ctx context.Context, req *v1.DeviceUptReq) (res *v1.DeviceUptRes, err error)

	// GetPageLst 分页获取设备列表
	GetPageLst(ctx context.Context, in *v1.DeviceGetPageLstReq) (out *api.PageLstRes[*mymodel.AppDeviceResponse], err error)

	// UptStatus 更新设备状态
	UptStatus(ctx context.Context, id int, status int) (err error)

	// Del 删除设备
	Del(ctx context.Context, id int) (err error)

	// GetOne 获取单条设备
	GetOne(ctx context.Context, id int) (out *entity.AppDevice, err error)

	// GetOptions 获取设备选项
	GetOptions(ctx context.Context, in *v1.DeviceGetOptionsReq) (out *v1.DeviceGetOptionsRes, err error)
	GetCopies(ctx context.Context, req *v1.DeviceGetCopiesReq) (res *v1.DeviceGetCopiesRes, err error)

	// GetByDeviceNo 根据设备编号获取设备信息
	GetByDeviceNo(ctx context.Context, deviceNo string) (out *entity.AppDevice, err error)
	GetDeviceNowReceivePolicy(ctx context.Context, deviceNo string) (conf *mymodel.ProductDeptConfigReceivePolicy, err error)
	GetDeviceNowSavePolicy(ctx context.Context, deviceNo string) (conf *mymodel.ProductDeptConfigSavePolicy, err error)
	GetDeviceCurrentDistributeTableInfo(ctx context.Context, deviceNo string, sampletime int64, flag string, forceCreate bool) (res *mymodel.DistributeTableResponse, err error)
	CreateDeviceDistributeDataTable(ctx context.Context, in *mymodel.DistributeTableResponse) (err error)
	ChangeDeviceOnlineStatus(ctx context.Context, deviceNo string, status int) (err error)
	ChangeVersion(ctx context.Context, deviceNo string, version string) (err error)
	GetAllDistributeTablesByWhere(ctx context.Context, where *mymodel.SearchDistributeTablesObj) (res []*mymodel.DistributeTableResponse, err error)
	GetReplaceDistributeTableName(ctx context.Context, table string, flag string) (res string)
	GetDistributeTableFlagByProductKey(ctx context.Context, productKey string) (res string)
	GetAeDataCacheFormatType(ctx context.Context, domain int, direction int) (res string)

	SendCmd(ctx context.Context, req *v1.DeviceSendCmdReq) (res *v1.DeviceSendCmdRes, err error)
	GetStateLogs(ctx context.Context, req *v1.DeviceGetStateLogsReq) (res *v1.DeviceGetStateLogsRes, err error)
	GetAstLogs(ctx context.Context, req *v1.DeviceGetAstLogsReq) (res *v1.DeviceGetAstLogsRes, err error)
}

var (
	localDevice IDevice
)

// Device 获取设备服务实例
func Device() IDevice {
	if localDevice == nil {
		panic("implement not found for interface IDevice, forgot register?")
	}
	return localDevice
}

// RegisterDevice 注册设备服务实例
func RegisterDevice(i IDevice) {
	localDevice = i
}
